<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--引用vue和axios-->
    <script src="js/vue/dist/vue.js"></script>
    <script src="js/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
</head>
<body>

    <div id="app">
    </div>

</body>


<script type="text/javascript">

    new Vue({
        el:"#app",
        methods:{},
        mounted(){
            //获取当前页面的路径
            var url = location.href;
            //调用工具类截取出code
           var jsonObj =  parseUrlParams2Obj(url);
           //获取到code授权码
            var code = jsonObj.code;

            //发送请求
            this.$http.get("/login/weChat/"+code)
            .then(res=>{
                if(res.data.success){
                    // 1. 把key（token）， user  存localStorage中
                    localStorage.setItem("token",res.data.resultObj.token)
                    // JSON.stringify(logininfo) 把json对象转成json字符串
                    localStorage.setItem("logininfo",JSON.stringify(res.data.resultObj.logininfo))

                    // 2. 跳转后台首页
                    location.href="index.html";
                }else{  //没有绑定
                    //获取后端传来的openid和token
                    var param = res.data.resultObj;

                    //需要调转到绑定页面
                    location.href="binder.html"+param;

                }
            }).catch(res=>{

            })

        }
    })



</script>

</html>